<template>
  <BaseDialog title="未知问题回答内容配置" :handleCancel="handleCancel" :dialogVisible="props.dialogVisible">
    <BaseForm
      labelWidth="100px"
      type="rule"
      :handleOk="handleOk"
      :handleCancel="handleCancel"
      :items="formItems"
      v-model:form="ruleForm"
      :rules="rules"
    >
    </BaseForm>
  </BaseDialog>
</template>

<script setup lang="ts">
import { contentManagementService } from '@/api/contentManagement';
const props = defineProps({
  dialogVisible: {
    type: Boolean,
  },
  item: {
    type: Object,
  },
});
const emit = defineEmits(['update:dialogVisible']);

const formItems = ref([
  {
    name: '回答',
    key: 'answer',
    type: 'textarea',
    placeholder: '请输入回答内容。启用后，当遇到未知问题时，将会回复本内容',
    maxlength: '500',
  },
  {
    name: '状态',
    key: 'isDisable',
    type: 'switch',
    activeValue: 0,
    inactiveValue: 1,
  },
]);
const rules = reactive({
  answer: [{ required: true, message: '请输入', trigger: 'change' }],
  isDisable: [{ required: true, message: '请选择', trigger: 'change' }],
});
const ruleForm = ref({
  commonId: '',
  answer: '',
  isDisable: '',
});
const handleOk = () => {
  return contentManagementService.libCommonUpdate2({
    data: { ...ruleForm.value },
  });
};
const getUnknownCommon = () => {
  contentManagementService.getUnknownCommon({ data: {} }).then((res) => {
    ruleForm.value.commonId = res.data.commonId;
    ruleForm.value.answer = res.data.answer;
    ruleForm.value.isDisable = res.data.isDisable;
  });
};
const handleCancel = () => {
  emit('update:dialogVisible', false);
};
onMounted(() => {
  getUnknownCommon();
});
</script>

<style lang="scss" scoped></style>
